package com.ruoyi.test.config;

import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.ruoyi.test.utils.SentinelExceptionUtil;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @author: 吴文兵
 * @date: 2025-06-18 10:44
 */
@Configuration
public class RestTemplateConfig {
    @Bean
    @LoadBalanced // 必须开启，否者无法通过服务名访问
    //sentinel 配置
    @SentinelRestTemplate(blockHandler = "handleException", blockHandlerClass = SentinelExceptionUtil.class, fallback = "fallback", fallbackClass = SentinelExceptionUtil.class)
    public RestTemplate restTemplate()
    {
        return new RestTemplate();
    }

}